#include<linux/module.h>
#include<linux/sched.h>
#include<linux/pid.h>
#include<linux/kthread.h>
MODULE_LICENSE("GPL");

int my_function(void *argc)
{
	printk("in the kernel thread function\n");
	printk("the policy of current thread is:%d\n",current->policy);
	printk("the rt_priority of current thread is:%d\n",current->rt_priority);
	printk("the current pid is:%d\n",current->pid);
	return 0;
}

static int __init sched_setscheduler_init(void)
{
	struct task_struct *result;
	int result1;
	struct sched_param param;
	printk("into sched_setscheduler_init.\n");
	result=kthread_create_on_node(my_function,NULL,-1,"sched_setscheduler");

	wake_up_process(result);

	param.sched_priority=1;
	printk("the policy of the child thread is:%d\n",result->policy);
	printk("the rt_priority of the child thread is:%d\n",result->rt_priority);
	result1=sched_setscheduler(result,1,&param);
	printk("the new rt_policy of the child thread is:%d\n",result->policy);
	printk("the pid of new thread is:%d\n",result->pid);
	printk("the result of the sched_setscheduler is:%d\n",result1);
	printk("the current pid is:%d\n",current->pid);
	printk("out sched_setscheduler_init.\n");
	return 0;
}
static void __exit sched_setscheduler_exit(void)
{
	printk("Goodbye sched_setschedulter\n");
}
module_init(sched_setscheduler_init);
module_exit(sched_setscheduler_exit);
